//
//  SchoCustomSlider.m
//  Manager
//
//  Created by key on 16/5/13.
//  Copyright © 2016年 Scho. All rights reserved.
//

#import "SchoCustomSlider.h"

#define PROGRESS_HEIGHT                 10.0f
#define SLIDER_WIDTH                    34.0f
#define SLIDER_HEIGHT                   17.0f

@implementation SchoCustomSlider

- (instancetype)initWithFrame:(CGRect)frame minimumValue:(CGFloat)minimumValue maximumValue:(CGFloat)maximumValue andValue:(CGFloat)value minimumTrackTintColor:(UIColor *)minimumTrackTintColor maximumTrackTintColor:(UIColor *)maximumTrackTintColor withThumbImage:(UIImage *)thumbImage {
    
    if (self = [super initWithFrame:frame]) {
        
        self.continuous = YES;                                                  //设置只有在离开滑动条的最后时刻才触发滑动事件
        self.minimumValue = minimumValue;                                       //滑动条的最小值
        self.maximumValue = maximumValue;                                       //滑动条的最大值
        self.value = value;                                                     //滑动条的当前值
        
        [self setThumbImage:thumbImage forState:UIControlStateNormal];          //设置静态时的滑块显示图片
        [self setThumbImage:thumbImage forState:UIControlStateHighlighted];     //设置滑动时的滑块显示图片
        
        self.minimumTrackTintColor = minimumTrackTintColor;                     //进度的颜色
        self.maximumTrackTintColor = maximumTrackTintColor;                     //剩余的颜色
        //添加UIControl的委托事件
        [self addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
    }
    return self;
}


- (void)sliderValueChanged:(SchoCustomSlider *)slider {
    
    if (self.didSliderChange) {
        self.didSliderChange(slider);
    }
}

#pragma mark -
- (CGRect)trackRectForBounds:(CGRect)bounds {
    
    return CGRectMake(CGRectGetMinX(bounds), CGRectGetMinY(bounds), CGRectGetWidth(bounds), PROGRESS_HEIGHT);
}



@end
